//package com.daocao.hua.activity;
//
//import android.annotation.TargetApi;
//import android.content.Intent;
//import android.graphics.Typeface;
//import android.os.Build;
//import android.os.Bundle;
//import android.support.v4.content.ContextCompat;
//import android.text.TextUtils;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.LinearLayout;
//import android.widget.TextView;
//import android.widget.Toast;
//
//import com.daocao.hua.R;
//import com.daocao.hua.api.callback.LoanDetailContract;
//import com.daocao.hua.api.requestInfo.LoanDetailRequest;
//import com.daocao.hua.constant.Const;
//import com.daocao.hua.event.OnHomeEventMsg;
//import com.daocao.hua.impl.RepayInfoImpl;
//import com.daocao.hua.http.InfoCallBack;
//import com.daocao.hua.model.BankListModel;
//import com.daocao.hua.model.LoanDetailModel;
//import com.daocao.hua.model.ResponseModel;
//import com.daocao.hua.util.ToastUtil;
//import com.daocao.hua.util.Util;
//import com.daocao.hua.view.CircularProgress;
//
//import org.greenrobot.eventbus.EventBus;
//
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * 借款详情界面
// */
//public class LoanDetailActivity extends BaseActivity
//        implements OnClickListener, LoanDetailContract.View {
//
//    private String dealId;
//    private CircularProgress loading;
//    private String mMoney;
//    private TextView deadline, money, loanDay, mLoanText, loanMoney, loanTip, day, title, repayBtn, check, repayMoney, serviceMoney, overdue1, overdue2, repayDate, changeCard, bindTitle, bindText, cardName, cardNum, cardText;
//    private LinearLayout repayView, overdueView, loanView, cardView, bindView;
//    private TextView dayTv;
//    private boolean isRepay = false;
//    private String overdueMoney;
//    private float rMoney;
////    private Typeface fontFace;
//    private static String id;
//    private LoanDetailRequest api;
//
//
//    protected void onCreate(Bundle paramBundle) {
//        super.onCreate(paramBundle);
//        setBaseContentView(R.layout.loan_detail_activity);
//        baseInitView(this, "LoanDetailActivity", Const.ViewType.ACTIVITY);
//        initView();
//    }
//
//    private void initView() {
//        api = LoanDetailRequest.create();
//        api.attachView(this);
////        fontFace = Application.getInstance().typeface;
//        setTitleText(getResources().getString(R.string.loan_detail2));
//        setBackIntent();
//        loading = ((CircularProgress) findViewById(R.id.progressBar));
//        money = ((TextView) findViewById(R.id.money));
//        deadline = ((TextView) findViewById(R.id.deadline));
//        loanMoney = ((TextView) findViewById(R.id.loan_money));
//        mLoanText = ((TextView) findViewById(R.id.tv_loan_day));
//        loanDay = ((TextView) findViewById(R.id.loan_day));
//        loanTip = ((TextView) findViewById(R.id.loan_tip));
//        dayTv = ((TextView) findViewById(R.id.day_tv));
////        mTishi = (TextView) findViewById(R.id.tv_tishi);
//        check = ((TextView) findViewById(R.id.check));
//        check.setOnClickListener(this);
//        repayView = ((LinearLayout) findViewById(R.id.repay_view));
//        overdueView = ((LinearLayout) findViewById(R.id.overdue_view));
//        cardView = (LinearLayout) findViewById(R.id.card_view);
//        bindView = (LinearLayout) findViewById(R.id.bind_view);
//        bindView.setOnClickListener(this);
//        loanView = (LinearLayout) findViewById(R.id.loan_view);
//        title = (TextView) findViewById(R.id.title);
//        day = (TextView) findViewById(R.id.day);
//        repayMoney = (TextView) findViewById(R.id.repay_money);
//        serviceMoney = (TextView) findViewById(R.id.service_money);
//        overdue1 = (TextView) findViewById(R.id.overdue1);
//        overdue2 = (TextView) findViewById(R.id.overdue2);
//        repayDate = (TextView) findViewById(R.id.repay_date);
//        changeCard = (TextView) findViewById(R.id.change_card);
//        changeCard.setOnClickListener(this);
//        repayBtn = (TextView) findViewById(R.id.repay_now);
//        repayBtn.setOnClickListener(this);
//        bindTitle = ((TextView) findViewById(R.id.bind_title));
//        bindText = ((TextView) findViewById(R.id.bind_text));
//        cardText = ((TextView) findViewById(R.id.card_text));
//        cardName = ((TextView) findViewById(R.id.card_name));
//        cardNum = ((TextView) findViewById(R.id.card_num));
//
//        id = getIntent().getStringExtra("id");
//
//    }
//
//    private void sendBroadcast() {
//
//        Map<String, String> map = new HashMap<>();
//        map.put("type", Const.SendType.UPDATE_REPAY);
//        EventBus.getDefault().post(new OnHomeEventMsg(map));
//    }
//
//
//    /**
//     * 是否显示加载框
//     *
//     * @param b
//     */
//    private void showLoading(boolean b) {
//        if (loading != null) {
//            if (b)
//                loading.setVisibility(View.VISIBLE);
//            else
//                loading.setVisibility(View.GONE);
//        }
//    }
//
//    public void onClick(View paramView) {
//        switch (paramView.getId()) {
//            default:
//                return;
//            case R.id.repay_now:
//                if (!repayBtn.getText().equals(getString(R.string.repay_now))) {
//                    Util.startActivity(this, BankActivity.class);
//                } else {
//                    if (isRepay)
//                        getNormalRepay();
//                    else {
//                        Intent intent = new Intent(this, PaySelectNewV2Activity.class);
//                        intent.putExtra("deal_id", dealId);
//                        intent.putExtra("money", rMoney + "");
//                        intent.putExtra("overdue", overdueMoney);
//                        startActivity(intent);
//                        overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                    }
//                }
//                break;
//            case R.id.check:
//                Intent intent = new Intent(this, LoanAgreementActivity.class);
//                intent.putExtra("type", 0);
//                intent.putExtra("deal_id", dealId);
//                startActivity(intent);
//                overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//                break;
//            case R.id.bind_view:
//            case R.id.change_card:
//                Util.startActivity(this, BankActivity.class);
//                break;
//        }
//    }
//
//    @Override
//    protected void onResume() {
//        super.onResume();
//        showLoading(true);
//        getLoanDetail(id);
//    }
//
//    protected void onDestroy() {
//        super.onDestroy();
//        api.detachView();
//    }
//
//    /**
//     * 余额还款
//     */
//    private void getNormalRepay() {
//        new RepayInfoImpl().getNormalRepay(this, dealId, "0", new InfoCallBack() {
//            public void onFailure(String paramAnonymousString) {
//                ToastUtil.makeText(getApplicationContext(), paramAnonymousString, Toast.LENGTH_SHORT).show();
//                repayResultActivity(0);
//            }
//
//            public void onSuccess(Object paramAnonymousObject) {
//                ResponseModel model = (ResponseModel) paramAnonymousObject;
//                ToastUtil.makeText(getApplicationContext(), model.getMsg(), Toast.LENGTH_SHORT).show();
//                repayResultActivity(1);
//            }
//        });
//    }
//
//    private void repayResultActivity(int type) {
//        Intent intent = new Intent(this, RepayResultActivity.class);
//        intent.putExtra("type", type);
//        intent.putExtra("deal_id", dealId);
//        intent.putExtra("money", mMoney);
//        intent.putExtra("overdue", overdueMoney);
//        startActivity(intent);
//        overridePendingTransition(R.anim.right_enter, R.anim.left_out);
//    }
//
//
//    /**
//     * 获取借款详情
//     */
//    private void getLoanDetail(String id) {
//        api.getLoanDetail(id);
//    }
//
//    private void setData(LoanDetailModel model) {
//
//        dealId = model.getData().getId() + "";
//        mLoanText.setText(getString(R.string.loan_day) + "(" + getString(R.string.day) + ")");
//        title.setText(model.getData().getKeyword() + "(" + getString(R.string.yuan) + ")");
//        if (model.getData().getMoney_format().contains("￥"))
//            money.setText(model.getData().getMoney_format().replace("￥", ""));
//        else money.setText(model.getData().getMoney_format());
////        money.setTypeface(fontFace);
//        if (model.getData().getBorrow_money_format().contains("￥"))
//            loanMoney.setText(model.getData().getBorrow_money_format().replace("￥", ""));
//        else loanMoney.setText(model.getData().getBorrow_money_format());
//        if (model.getData().getTerm_of_loan().contains(getString(R.string.day)))
//            loanDay.setText(model.getData().getTerm_of_loan().replace(getString(R.string.day), ""));
//        else loanDay.setText(model.getData().getTerm_of_loan());
//        if (model.getData().getServices_fee_format().contains("￥"))
//            loanTip.setText(model.getData().getServices_fee_format().replace("￥", ""));
//        else loanTip.setText(model.getData().getServices_fee_format());
//
//        mMoney = model.getData().getMoney_format();
//        if (!TextUtils.isEmpty(mMoney)) {
//            if (mMoney.contains("￥")) mMoney = mMoney.replace("￥", "");
//            if (mMoney.contains(",")) mMoney = mMoney.replace(",", "");
//        }
//        rMoney = Float.parseFloat(mMoney) - model.getData().getUser_balance();
//
//        switch (model.getStatus()) {
//            case 1: // 审核中-未绑定银行卡
//            case 2: // 审核中-已绑定银行卡
//            case 4: // 待放款-未绑定银行卡
//            case 5: // 待放款-已绑定银行卡
//                check(model);
//                break;
//            case 6: //未还款
//                unRepay(model);
//                break;
//            case 7: //已还清
//                alreadyRepay(model);
//                break;
//        }
//    }
//
//    /**
//     * 审核中
//     *
//     * @param model
//     */
//    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
//    private void check(LoanDetailModel model) {
//        loanView.setVisibility(View.GONE);
////        mTishi.setVisibility(View.VISIBLE);
//        repayView.setVisibility(View.GONE);
////        mTishi.setText(model.getData().getContent());
//
//        if (model.getStatus() == 1) {
//            bindTitle.setText(getString(R.string.bind_card));
//            bindText.setText(getString(R.string.apply_for_check_have_card));
//            bindView.setVisibility(View.VISIBLE);
//            bindView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.bind_card_orange_bg));
////            mTishi.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.default_orange_color));
////            mTishi.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.yellow_light_color));
//        }
//        if (model.getStatus() == 4) {
//            bindTitle.setText(getString(R.string.bind_card_now));
//            bindText.setText(model.getData().getMemo());
//            bindView.setVisibility(View.VISIBLE);
//            bindView.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.bind_card_red_bg));
////            mTishi.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.default_blue_color));
////            mTishi.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.blue_light_color));
//        }
//        if (model.getStatus() == 2) {
//            cardView.setVisibility(View.VISIBLE);
//            changeCard.setVisibility(View.VISIBLE);
//            cardText.setText(getString(R.string.apply_for_check_have_card));
////            mTishi.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.default_orange_color));
////            mTishi.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.yellow_light_color));
//
////            getBankList();
//            api.getBankList();
//        }
//        if (model.getStatus() == 5) {
//            cardView.setVisibility(View.VISIBLE);
//            changeCard.setVisibility(View.VISIBLE);
//            cardText.setText(getString(R.string.apply_for_success_have_card));
////            mTishi.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.default_blue_color));
////            mTishi.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.blue_light_color));
//
////            getBankList();
//            api.getBankList();
//        }
//    }
//
//    /**
//     * 未还款
//     *
//     * @param model
//     */
//    @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
//    private void unRepay(LoanDetailModel model) {
//        repayView.setVisibility(View.GONE);
//        repayBtn.setVisibility(View.VISIBLE);
//        deadline.setVisibility(View.VISIBLE);
//        day.setVisibility(View.VISIBLE);
//        overdueView.setVisibility(View.VISIBLE);
//        overdueMoney = model.getData().getImpose_money_format();
//        repayBtn.setText(getString(R.string.repay_now));
//        mLoanText.setText(getString(R.string.loan_day));
//
//        if (model.getData().getImpose_money_format().contains("￥"))
//            overdue1.setText(model.getData().getImpose_money_format().replace("￥", ""));
//        else overdue1.setText(model.getData().getImpose_money_format());
//
//        if (model.getData().getUser_balance() >= model.getData().getNeed_repay_money())
//            isRepay = true; //足够余额，跳过支付宝
//        else isRepay = false;
//
//
//        if (model.getData().getImpose_days() > 0) {
//            day.setText(model.getData().getImpose_days() + "");
//            deadline.setText(model.getData().getRepay_day_format() + "前还款,已逾期");
//        } else {
//            deadline.setText(model.getData().getRepay_day_format() + "前还款,剩");
//            day.setText(model.getData().getRemaining_days() + "");
//        }
//    }
//
//    /**
//     * 已还清
//     */
//    private void alreadyRepay(LoanDetailModel model) {
//        repayView.setVisibility(View.VISIBLE);
//        repayBtn.setVisibility(View.GONE);
//        mLoanText.setText(getString(R.string.loan_day));
//        if (model.getData().getTrue_self_money_format().contains("￥"))
//            repayMoney.setText(model.getData().getTrue_self_money_format().replace("￥", ""));
//        else repayMoney.setText(model.getData().getTrue_self_money_format());
//        if (model.getData().getTrue_services_money_format().contains("￥"))
//            serviceMoney.setText(model.getData().getTrue_services_money_format().replace("￥", ""));
//        else serviceMoney.setText(model.getData().getTrue_services_money_format());
//        if (model.getData().getTrue_impose_money_format().contains("￥"))
//            overdue2.setText(model.getData().getTrue_impose_money_format().replace("￥", ""));
//        else overdue2.setText(model.getData().getTrue_impose_money_format());
//        repayDate.setText(model.getData().getTrue_repay_date());
//        deadline.setText("好借好还，再借不难");
//        dayTv.setVisibility(View.GONE);
//    }
//
//
//    @Override
//    public void showError() {
//
//    }
//
//    @Override
//    public void complete() {
//        showLoading(false);
//    }
//
//    @Override
//    public void onRequestStart() {
//        showLoading(true);
//    }
//
//    /**
//     * 获取已绑定银行卡
//     */
//    @Override
//    public void getBankListSuccess(BankListModel model) {
//        cardName.setText(model.getBanks().get(0).getName());
//        cardNum.setText(model.getBanks().get(0).getBankcard().replaceAll("(.{4})", "$1 "));
////        cardNum.setTypeface(fontFace);
//    }
//
//    @Override
//    public void getLoanDetailSuccess(LoanDetailModel item) {
//        setData(item);
//    }
//
//}
